<?php 
if(!defined('ADMINPX') || !defined('ADMIN')) {
	exit('Access Denied');
}
$id=$_GET['id']; 
$act=$_GET['act'];
$templates=$_GET['templates'];
$yid=$_GET['yid']; 
$type=$_GET['type'];
 
if($act =='zjok'){
	 $_POST['value']=authcode($_POST['value'],'ok');
	 if(!$_POST[adminpost]){
	    echo"提交出错<br/>";
	 }elseif($db->insert('index',array('id ' => 'NULL' ,'templates' => $templates,'fid ' => $yid,'name ' => $_POST[name],'value ' => $_POST[value],'type ' => $_POST[type],'px ' => $_POST[px],'yc ' => $_POST[yinc]))){
	    echo"增加栏目成功<br/>";
	 }else{
		  echo"增加栏目失败<br/>";
	 }
	 deldir('cache/index');
   echo "正在自动返回.......<br/><a href=\"admin.php?action=design&act=index&templates=$templates&yid=$yid\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=design&act=index&templates=$templates&yid=$yid'>";
}else if($act =='xgok'){
	 if(!$_POST[adminpost]){
	    echo"提交出错<br/>";
	 }else{
	 	 $_POST['value']=authcode($_POST['value'],'ok');
	 	 $db->update('index',array('name' => $_POST[name],'type' => $_POST[lx],'value' => $_POST[value],'px' => $_POST[px],'yc' => $_POST[yinc] )," `id` =$id");
	   echo"修改成功<br/>"; 
	 }
	 deldir('cache/index');
   echo "正在自动返回.......<br/><a href=\"admin.php?action=design&act=index&templates=$templates&yid=$yid\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=design&act=index&templates=$templates&yid=$yid'>";
}else if($act=='scts'){
	 echo'<div class="admin">删除栏目</div>注意：删除后不可恢复，包括分类内容！<br/>';
	 echo"<a href=\"admin.php?action=design&&act=sc&id=$id&templates=$templates&yid=$yid\">确定删除</a><br/>";
}else if($act=='sc'){
	 $row=$db->get_one('index'," `id` ='$id'",''); 
	 if($row[type]=='7'){
	    $db->delete('index'," `fid` = '$id'");
   }
   $db->delete('index'," `id` = '$id'");
	 echo"删除成功<br/>";
   echo "正在自动返回.......<br/><a href=\"admin.php?action=design&act=index&templates=$templates&yid=$yid\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=design&act=index&templates=$templates&yid=$yid'>";
}else if($act =='xg'){
   $row=$db->get_one('index'," `id` ='$id'",''); 
   if($row[type]==0){
    	$typename="文本"; 
    	$lxa='CHECKED';
   }else if($row[type]==1){
	    $typename="ubb";
	    $lxb='CHECKED';
   }else if($row[type]==2){
	    $typename="HTML";
	    $lxc='CHECKED';
   }else if($row[type]==7){
	    $typename="新页面";
	    $URL='index.php?index='.$id.'';
   }
   if($row[type]==7 && $row[fid]=='0'){
	    $URL='<div class="admin_b">连接地址:(<a href="index.php?index='.$id.'">index.php?index='.$id.'</a>)</div>';
   }
   if($row[yc] == '1'){$yca='CHECKED';}else{$ycb='CHECKED';}
   if(authcode($row['value'],'DECODE')){
      $row['value']=authcode($row['value'],'DECODE');
   }
echo <<<end
<form method="POST" action="admin.php?action=design&&act=xgok&id=$id&yid=$yid&templates=$templates"> 
<div class="admin">类型:(<b>$typename</b>)</div>
$URL
栏目隐藏 
<input type="radio" $yca name="yinc" value="1" />隐藏
<input type="radio" $ycb name="yinc" value="0" />不隐藏<br/>
栏目类型 
end;
if($row[type] == '7'){
echo <<<end
<input type="radio" CHECKED name="lx" value="7" />新页面<br/>
end;
}else{
echo <<<end
<input type="radio" $lxa name="lx" value="0" />文本
<input type="radio" $lxb name="lx" value="1" />ubb
<input type="radio" $lxc name="lx" value="2" />HTML<br/>
end;
}
echo <<<end
栏目排序 <input  class="text" type="text" name="px" size="5" value="$row[px]" /><br/>
后台标题 <input  class="text" type="text" name="name" value="$row[name]" /><br/>
显示内容 (<a href="admin.php?action=wzgj&act=ubb">UBB帮助</a>)<br/>
<textarea  class="dktextarea" type="text" name="value" >$row[value]</textarea><br/> 
<input class="submit" type="submit" value="修改" name="adminpost"/> <br/> 
<a href="admin.php?action=design&&act=scts&id=$id&templates=$templates&yid=$yid"><font color="#ff0000"><b>删除栏目</b></font></a><br/>
end;
}else if($act =='zj'){
    if(empty($yid)){$yid=0;}
    if($type=='0'){ 
	     $typename="纯文本"; 
    }else if($type==1){
	     $typename="ubb";
    }else if($type==2){
	     $typename="HTML";
    }else if($type==7){
    	 $typename="新页面";
    }
echo <<<end
<form method="POST" action="admin.php?action=design&&act=zjok&yid=$yid&templates=$templates"> 
<input type="hidden" name="yid" value="$yid" />
<input type="hidden" name="type" value="$type" />
<div class="admin">类型: (<b><font color="#ff0000">$typename</font></b>)</div>
隐藏栏目
<select class="text" name="yinc"> 
<option value="0">不隐藏</option> 
<option value="1">隐藏</option>
</select><br/> 
栏目排序
<input class="text" type="text" name="px" size="10" value="1" /><br/> 
后台标题 <input  class="text" type="text" name="name" value="后台标题" /><br/>
显示内容 (<a href="admin.php?action=wzgj&act=ubb">UBB帮助</a>)<br/>
<textarea class="dktextarea" type="text" name="value" >显示内容</textarea><br/> 
<input class="submit" type="submit" value="增加" name="adminpost"/> 
end;
}else if($act =='pb'){
	if($templates){
echo <<<end
<div class="admin">==添加栏目==</div>
<div class="admin_a"> <a href="admin.php?action=design&act=zj&type=0&yid=$yid&templates=$templates">纯文本</a><br/> </div> 
<div class="admin_a"> <a href="admin.php?action=design&act=zj&type=1&yid=$yid&templates=$templates">UBB</a><br/> </div> 
<div class="admin_a"> <a href="admin.php?action=design&act=zj&type=2&yid=$yid&templates=$templates">HTML </a><br/> </div>
<div class="admin_a"> <a href="admin.php?action=design&act=zj&type=7&yid=$yid&templates=$templates">新页面</a><br/> </div> 
end;
}else{
echo <<<end
<div class="admin">==添加栏目==</div>
<div class="admin_a">操作出错，请返回！</div> 
end;
}
}else if($act =='index'){
  echo"<div class=\"admin\"> 首页排版 - <a href=\"admin.php?action=design&yid=$yid&templates=$templates&act=pb\"><font color=\"ff0000\">添加栏目</font></a></div><div class=\"admin_b\">"; 
  if(empty($yid)){
	   $design_sql=$db->query('index' ,"  `templates` ='$templates'  AND `fid` =0 ORDER BY `px` ASC ",''); 
  }else{ 
	   $design_sql=$db->query('index' ,"  `templates` ='$templates'  AND `fid` =$yid ORDER BY `px` ASC ",''); 
  } 
  $url=$_SERVER['REQUEST_URI'];
  while($ro=mysql_fetch_array($design_sql)){
      $name=Bingz_html($ro[name]);
	    if(!$name){
         $name='后台默认标题';
      }
	    if($ro[yc]==1){
         echo '<font color="#000000"><b>{隐}</b></font>';
      }
	    if($ro[type]=='7'){
		     echo "$ro[px].$name(<a href=\"admin.php?action=design&act=index&templates=$_GET[templates]&yid=$ro[id]\">内容编辑</a>)";
	    }else{
	    	 echo "$ro[px].$name";
	    }
	    if($ro[yc]==1){
         echo '<font color="#000000"><b>{/隐}</b></font>';
      }
echo <<<end
<a href="admin.php?action=design&&act=xg&id=$ro[id]&yid=$yid&templates=$templates"><font color="#ff0000"><b>{==修改==}</b></font></a><br/> 
end;
}
echo"</div>"; 
}else{
  echo"<div class=\"admin\">首页排版</div><font color=\"#ff0000\">选择模板</font>"; 
  $dir = opendir("templates/");
  while($file = readdir($dir)){
		if( $file !='.' && $file !='..' && !strpos($file,'.')){
      echo'<div class="admin_a"><b>'.$file.'</b>    <a href="admin.php?action=design&act=index&templates='.$file.'">首页排版</a></div>';
		}
	} 
  closedir($dir);
}
echo"<div class=\"admin_a\"><a href=\"admin.php?action=design\">返回网站排版</a></div>"; 
?>